/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Xceed.Silverlight.Data
{
  [DebuggerDisplay( "FilterGroup = {DebuggerDisplayFilterGroup}" )]
  public sealed class FilterGroupRequest
  {
    #region Constructor

    internal FilterGroupRequest( IEnumerable<FilterGroupValue> values )
    {
      if( values == null )
        throw new ArgumentNullException( "values" );

      if( !values.Any() )
        throw new ArgumentException( "At least one value must be specified.", "values" );

      m_values.AddRange( values );
      m_readOnlyValues = new ReadOnlyCollection<FilterGroupValue>( m_values );
    }

    #endregion

    #region Values Property

    public IList<FilterGroupValue> Values
    {
      get
      {
        return m_readOnlyValues;
      }
    }

    private ReadOnlyCollection<FilterGroupValue> m_readOnlyValues;
    private List<FilterGroupValue> m_values = new List<FilterGroupValue>();

    #endregion

    #region DebuggerDisplayFilterGroup Property

    // This property only purpose is to generate a string for the DebuggerDisplay attribute.
    private string DebuggerDisplayFilterGroup
    {
      get
      {
        StringBuilder sb = new StringBuilder();

        bool isFirstValue = true;
        foreach( FilterGroupValue filterGroupValue in m_values )
        {
          if( !isFirstValue )
          {
            sb.Append( "," );
          }
          else
          {
            isFirstValue = false;
          }

          object value = filterGroupValue.Value;

          sb.Append( " {" );
          if( value == null )
          {
            sb.Append( "#null#" );
          }
          else
          {
            sb.Append( value.ToString() );
          }
          sb.Append( "}" );
        }

        return sb.ToString();
      }
    }

    #endregion
  }
}
